class Solution
{
public:
    vector<int> vowelStrings(vector<string> &words, vector<vector<int>> &queries)
    {
        int n = words.size();
        vector<int> countPreSum(n + 1, 0);

        auto isVowel = [](char c)
        {
            return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
        };

        for (int i = 0; i < n; ++i)
        {
            if (isVowel(words[i][0]) && isVowel(words[i][words[i].size() - 1]))
            {
                countPreSum[i + 1] = countPreSum[i] + 1;
            }
            else
            {
                countPreSum[i + 1] = countPreSum[i];
            }
        }

        vector<int> result;
        for (auto &query : queries)
        {
            result.push_back(countPreSum[query[1] + 1] - countPreSum[query[0]]);
        }
        return result;
    }
};